//
//  LKUFPictureRowCell.m
//  Mideleague_Shop
//
//  Created by Zhiwang on 2020/6/3.
//  Copyright © 2020 Zhiwang. All rights reserved.
//

#import "LKUFPictureRowCell.h"
#import "LKUFPictureRow.h"
#import "LKServerAPI.h"

@interface LKUFPictureRowCell()

@property(nonatomic,strong)LKUFPictureRow *pictureRow;

@property(nonatomic,strong)LKBaseLabel *headerLabel;

@property(nonatomic,assign)NSInteger selectIndex;
@end

@implementation LKUFPictureRowCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
    }
    return self;
}

-(void)setRow:(__kindof UFRow *)row{
    _pictureRow = (LKUFPictureRow *)row;
    [super setRow:row];
    self.headerLabel = [LKBaseLabel labelWithFrame:CGRectMake(10, 15, WIDTH - 20, 15) text:_pictureRow.headerTitle textColor:COLOR_HEX(0x333333) font:[UIFont fontWithName:@"PingFangSC-Regular" size:16] textAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:self.headerLabel];
    for (NSInteger i = 0; i < _pictureRow.pictureNumbers; i++) {
        UIImageView *pictureImageV = [[UIImageView alloc] initWithFrame:CGRectMake(10 + (i % 2)*(pictureWidth + 10), 45 + (i/2) * (pictureHeight + 10), pictureWidth, pictureHeight)];
        pictureImageV.backgroundColor = COLOR_HEX(0xF5F5F5);
        pictureImageV.userInteractionEnabled = YES;
        pictureImageV.tag = 1000 + i;
        [pictureImageV sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",ServerlUrl,_pictureRow.picturesArray[i]]] placeholderImage:[UIImage imageNamed:@""]];
       UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pictureActionChoose:)];
        [pictureImageV addGestureRecognizer:tap];
        [self.contentView addSubview:pictureImageV];
        LKBaseLabel *pictureIntroLabel = [LKBaseLabel labelWithFrame:CGRectMake(0, pictureHeight - 20, pictureWidth, 20) text:_pictureRow.titlesPlaceArray[i] textColor:[UIColor whiteColor] font:[UIFont fontWithName:@"PingFangSC-Regular" size:14] textAlignment:NSTextAlignmentCenter];
        pictureIntroLabel.backgroundColor = COLOR_HEX(0x000000);
        pictureIntroLabel.alpha = 0.29;
        [pictureImageV addSubview:pictureIntroLabel];
    }
}
//手势点击
-(void)pictureActionChoose:(UITapGestureRecognizer *)tap{
    _pictureRow.selectImageV = (UIImageView *)tap.view;
    if (_pictureRow.uploadImageBlock) {
        _pictureRow.uploadImageBlock(tap.view.tag, _pictureRow.selectImageV);
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
}

@end
